<template>
    <el-dialog :visible.sync="dialog" :title="isAdd ? '资源审核' : '资源审核'" append-to-body width="450px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="100px" append-to-body>
            <el-form-item label="是否通过" prop="checkStatus" >
                <el-select v-model="form.checkStatus" clearable  filterable placeholder="请选择是否通过" style="width: 250px;" @change="getTitle">
                    <el-option
                        v-for="item in codestuas"
                        :key="item.id"
                        :label="item.name"
                        :value="item.id">
                    </el-option>
                </el-select>
            </el-form-item>

            <el-tooltip class="tooltip" placement="top" effect="light">
                <div slot="content">
                      <p>1：“学校审核通过”是指提交的资源在本校可见</p>
                      <p>2：“不通过”是指资源涉嫌违规违法或者其他因素</p>
                      <p>3：“审核通过并提交区域”是指提交区域审核，区域审核通过即代表发布</p>                     
                </div>
                <i class="el-icon-question"></i>
            </el-tooltip>

        </el-form>

        <div slot="footer" class="dialog-footer">
            <el-button type="text" @click="cancel">取消</el-button>
            <el-button :loading="loading" type="primary" @click="doSubmit" >{{btn_title}}</el-button>
        </div>
    </el-dialog>
</template>

<script>
import { shcCheck } from '@/api/request'
import { resourcesSchool } from '@/api/data'
export default {
    props: {
        isAdd: {
          type: Boolean,
          required: true
        },
    },
    data() {
        return {
            btn_title:'保存',
            disabled:true,
            loading: false, dialog: false, permissions: [],
            form: {
                id:'',
                checkStatus:'',
                resCover:'',      //封面
                resUrl:'',        //地址
                resName:'',      //视频标题
                useType:'',      //视频类型
                remark:'',       //简介
                resPhases:'',    //学段
                resGrade:'',     //年级
                resCourses:'',   //科目
                resStatus:''      //隐私
            },
            rules: {
                checkStatus:[
                    { required: true, trigger: 'blur',message: '请选择是否通过',},
                ],
            },
            codestuas:[
                {
                    id: 2,
                    name: '学校审核通过'
                },
                {
                    id: 3,
                    name: '不通过'
                },
                {
                    id: 4,
                    name: '审核通过并提交到区域'
                },
            ]
        }
    },
    methods: {
        cancel(){
            this.dialog  = false
        },
        getTitle(){
            if (this.form.checkStatus == 3) {
                this.btn_title = "保存"
            }
            if (this.form.checkStatus == 2) {
                this.btn_title = "保存"
            }
            if (this.form.checkStatus == 4) {
                this.btn_title = "保存并提交区域审核"
            }
        },
        doSubmit(){
            this.$refs['form'].validate((valid) => {
                if (valid){
                    if (this.form.checkStatus == 2 || this.form.checkStatus == 3) {
                        this.doSave()
                        return
                    }
                    if (this.form.checkStatus == 4){
                        this.doAdd()
                        return
                    }
                    
                }else {
                    return false
                }

            })

        },
        doSave(){
            shcCheck(this.form).then(res => {
                this.$notify({
                    title: '保存成功',
                    type: 'success',
                    duration: 2500
                })
                this.dialog = false
                this.$parent.init()
            })
        },
        async doAdd(){
            this.form.checkStatus = 2
            shcCheck(this.form).then(res => {
                resourcesSchool(this.form.id).then(res => {
                    this.$notify({
                        title: '提交区域成功',
                        type: 'success',
                        duration: 2500
                    })
                    this.dialog = false
                    this.$parent.init()
                })
            })
        },

    },



}
</script>


<style scoped lang="scss">
.el-form-item--mini.el-form-item, .el-form-item--small.el-form-item{
    display: inline-block;
}
</style>
